package org.edu.controller;
import org.apache.struts2.ServletActionContext;
import org.edu.bean.Taxidentification;

import org.edu.common.PageView;
import org.edu.common.QueryResult;

import javax.annotation.Resource;
import org.edu.service.TaxidentificationService;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class TaxidentificationController extends ActionSupport {
	private Taxidentification entity;
	@Resource
	private TaxidentificationService taxidentificationservice;
	private Integer page = 1;
	private String idnumber;
	private Integer id;

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
	public Taxidentification getEntity() {
		return entity;
	}
	public void setEntity(Taxidentification entity) {
		this.entity = entity;
	}
	@Override
	public String execute() throws Exception {
		try {
			
			taxidentificationservice.save(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return "success";
	}
	public String input() throws Exception {
		try{
			taxidentificationservice.save(entity);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "input";
	}

	public String list() throws Exception{
			PageView<Taxidentification> pageView = new PageView<Taxidentification>(20,page);
			QueryResult<Taxidentification> result = taxidentificationservice.getQueryResult(pageView.getFirstResult(),pageView.getMaxresult());
			pageView.setQueryResult(result);
			ServletActionContext.getRequest().setAttribute("pageView",pageView);
			return SUCCESS;
		}
	public String delete() {
		try {
			taxidentificationservice.delete(id);
			PageView<Taxidentification> pageView = new PageView<Taxidentification>(20,page);
			QueryResult<Taxidentification> result = taxidentificationservice.getQueryResult(pageView.getFirstResult(),pageView.getMaxresult());
			pageView.setQueryResult(result);
			ServletActionContext.getRequest().setAttribute("pageView",pageView);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
		 
	}
	public String findByIdNumber() {
//		 System.out.println("1:"+idnumber);
//		 Taxidentification obj = taxidentificationservice.queryByIdNumber(idnumber);
//		 System.out.println("2:"+obj.getTll_idnumber());
//		 ServletActionContext.getRequest().setAttribute("entity",obj);
		PageView<Taxidentification> pageView = new PageView<Taxidentification>(20,page);
		if(idnumber != null && !"".equals(idnumber.trim())){
			QueryResult<Taxidentification> result = taxidentificationservice.getQueryResult(pageView.getFirstResult(),pageView.getMaxresult(),"o.tll_idnumber=?",new Object[]{idnumber.trim()});
			pageView.setQueryResult(result);
			ServletActionContext.getRequest().setAttribute("pageView",pageView);
		}
		return SUCCESS;
	}
	public String update() throws Exception{
		try {
		
			
			
			taxidentificationservice.save(entity);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "update";
		
	}
	public String getIdnumber() {
		return idnumber;
	}
	public void setIdnumber(String idnumber) {
		this.idnumber = idnumber;
	}
	
}
